package service.managed;

import java.util.Dictionary;
import java.util.Hashtable;

import library.service.Book;
import library.service.LibraryService;

import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedService;

import service.library.OsgiLibraryServiceImpl;

public class ManagedServiceLib implements ManagedService {

	private LibraryService libraryService;

	public ManagedServiceLib(LibraryService libraryService) {
		if (libraryService == null) {
			throw new IllegalArgumentException(
					"Null-pointed libraryService input argument.");
		}
		this.libraryService = libraryService;
	}

	public void updated(Dictionary properties) throws ConfigurationException {

		System.out.println("ManagedServiceLib updated() method");
		String[] bookNames = (String[]) properties.get("bookNames");
		if (bookNames != null) {
			for (int i = 0; i < bookNames.length; i++) {
				Dictionary dict = new Hashtable();
				dict.put("name", bookNames[i]);
				libraryService.addBook(dict);
			}
		}
	}
}
